﻿@using Blazor.FlexGrid.Components
@using Blazor.FlexGrid.Demo.Shared
@using Blazor.FlexGrid.DataAdapters
@page "/masterdetailgrid"
@inject CustomerService CustomerService
@inject LazyLoadedTableDataAdapter<Order> OrdersLazyLoadedTableDataAdapter
@inject MasterTableDataAdapterBuilder<Customer> MasterAdapterBuilder

<h1>Customers</h1>

<GridView DataAdapter="@customersMasterDataAdapter" PageSize="5"></GridView>

@code
        {
    CollectionTableDataAdapter<Customer> customerDataAdapter;
    CollectionTableDataAdapter<CustomerAddress> customerAddressesDataAdapter;
    MasterTableDataAdapter<Customer> customersMasterDataAdapter;

    protected override void OnInitialized()
    {
        var customers = CustomerService.Customers();
        var customersAddresses = CustomerService.CustomersAddresses();
        customerDataAdapter = new CollectionTableDataAdapter<Customer>
            (customers);
        customerAddressesDataAdapter = new CollectionTableDataAdapter<CustomerAddress>
            (customersAddresses);

        customersMasterDataAdapter = MasterAdapterBuilder
        .MasterTableDataAdapter(customerDataAdapter)
        .WithDetailTableDataAdapter(OrdersLazyLoadedTableDataAdapter)
        .WithDetailTableDataAdapter(customerAddressesDataAdapter)
        .Build();
    }
}
